package com.example.arithmeticleetcode.leetcode.october;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Calendar;
import java.util.Date;
import java.util.Vector;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-10-23 10:22
 **/
public class Demo14 {

    public static void main(String[] args) {
        System.out.println(dayOfTheWeek(24, 10, 2020));
    }

    public static String dayOfTheWeek(int day, int month, int year) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(year, month - 1, day);
        System.out.println(calendar.getTime());
        int firstDayOfWeek = calendar.getFirstDayOfWeek();
        System.out.println(firstDayOfWeek);
        System.out.println("-------------------");

        LocalDate localDate = LocalDate.of(year, month, day);
        DayOfWeek dayOfWeek = localDate.getDayOfWeek();
        System.out.println(dayOfWeek);
        return dayOfWeek.toString().charAt(0) + dayOfWeek.toString().substring(1).toLowerCase();
    }

    public static String dayOfTheWeek1(int day, int month, int year) {
        int y = 1971, d = 0, m = 0, res = 0;
        int[] monday = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        for (; y < year; y++) {
            if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0) res += 366;
            else res += 365;
        }
        if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0) monday[1] = 29;
        for (; d < month - 1; d++) {
            res += monday[d];
        }
        res += day;
        res = (res - 1) % 7;
        switch (res) {
            case 0:
                return "Friday";
            case 1:
                return "Saturday";
            case 2:
                return "Sunday";
            case 3:
                return "Monday";
            case 4:
                return "Tuesday";
            case 5:
                return "Wednesday";
            case 6:
                return "Thursday";
            default:
                break;
        }
        return "";
    }
}
